package com.hr.controller;

import com.hr.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("emp")

public class EmployeeController {
    //将连接池注入到ioc容器
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @GetMapping("list")
    public List<Employee> list(){
        String sql="select * from t_emp";
        List<Employee> list=jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(Employee.class));
        return list;
    }
}
